<?php
/**
 * Created by : Sandi Rizky Kharisma (sandi.informatics08@gmail.com)
 * This Class Generated for CRUD purpose only
 */
class anggota extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();

        $this->load->library('auth');
        $this->load->library('base');
        $this->load->library('ajaxresponse');
        $this->load->library('datatables');
        $this->load->model('crud/m_anggota');
    }

    public function index()
    {
        $this->crud();
    }

    public function crud()
    {
        $this->auth->is_logged_in('form/login');
        $this->base->head_html('Tabel anggota');
        $this->load->model("crud/m_unit");
        $this->load->model("crud/m_devisi");
        $this->load->model("crud/m_kota");
        $data["Unit"] = $this->m_unit->get();
        $data["Devisi"] = $this->m_devisi->get();
        $data["Kota"] = $this->m_kota->get();
        $this->load->view('crud/anggota', $data);
    }

    public function get_all1()
    {
        $this->datatables
           ->from('anggota')
            ->where("STATUS", 1);

        echo $this->datatables->generate();
    }

    public function get_all()
    {
        $this->auth->is_logged_in('form/login');
        $this->response = new ajaxresponse();
        $this->response->data = $this->m_anggota->get()->result();
        echo json_encode($this->response);
    }
    
    public function get($id)
    {
        $this->auth->is_logged_in('form/login');
        $this->response = new ajaxresponse();
        $this->response->data = $this->m_anggota->get_one($id)->result_array();
        echo json_encode($this->response);
    }

    public function add()
    {
        $this->auth->is_logged_in('form/login');
        $this->response = new ajaxresponse();
        $this->response->data = $this->m_anggota->insert();
        echo json_encode($this->response);
    }

    public function update($id)
    {
        $this->auth->is_logged_in('form/login');
        $this->response = new ajaxresponse();
        $this->response->data = $this->m_anggota->update($id);
        echo json_encode($this->response);
    }
    
    public function delete($id)
    {
        $this->auth->is_logged_in('form/login');
        $this->response = new ajaxresponse();
        $this->response->data = $this->m_anggota->delete($id);
        echo json_encode($this->response);
    }
}
?>